import CommonBaseSchema from '#common/base_schema'

export default class extends CommonBaseSchema {
  protected tableName = 'goods'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()
      table.integer('fk_shop_id').unsigned().notNullable().references('shops.id').comment('商店ID')

      table
        .integer('fk_category_id')
        .unsigned()
        .notNullable()
        .references('dicts.id')
        .comment('分类ID')

      table
        .integer('fk_warehouse_id')
        .unsigned()
        .notNullable()
        .references('dicts.id')
        .comment('默认仓库ID')

      table
        .integer('fk_supplier_id')
        .nullable()
        .unsigned()
        .references('dicts.id')
        .comment('供应商ID')

      table.integer('fk_buy_unit_id').unsigned().references('dicts.id').comment('成本单位ID')

      table.integer('buy_unit_number').unsigned().defaultTo(1).comment('置换数量')
      table.integer('buy_unit_price').unsigned().defaultTo(0).comment('成本')

      table.integer('fk_standard_unit_id').unsigned().references('dicts.id').comment('正常单位ID')

      table.string('name', 60).comment('商品名称')
      table.string('spec', 60).defaultTo('').comment('规格')
      table.string('place', 60).defaultTo('').comment('位置')
      table.integer('normal_price').unsigned().defaultTo(0).comment('标准价格')
      table.string('bar_code', 100).unique().defaultTo('').comment('条形码')
      table.tinyint('status').unsigned().defaultTo(1).comment('状态')
      table.string('memo', 255).defaultTo('').comment('备注')

      this.defineCommonColumns(table)
      table.comment('商品表')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
